//
//  ReadTableViewCell.m
//  Lucky28
//
//  Created by zr on 2018/7/31.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "ReadTableViewCell.h"

@interface ReadTableViewCell ()

@property (nonatomic, weak)UIImageView * backImageView;
@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UIView * verLineView;
@property (nonatomic, weak)UIImageView * iconImageView;
@property (nonatomic, weak)UILabel * contentLabel;
@property (nonatomic, weak)UIImageView * darkImageView;
@property (nonatomic, weak)UIImageView * eyeImageView;
@property (nonatomic, weak)UILabel * readNumLabel;

@end

@implementation ReadTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setModel:(ReadModel *)model{
    
    _model = model;
    
    NSURL * url = [NSURL URLWithString:model.images];
    
    [self.backImageView sd_setImageWithURL:url placeholderImage:ImageNamed(@"tu1")];
    self.contentLabel.text = model.title;
    self.readNumLabel.text = [NSString stringWithFormat:@"%@",model.read];
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor whiteColor];
    
    
    UIImageView * backImageView = [UIImageView new];
    
//    backImageView.image = ImageNamed(@"tu1");
    backImageView.backgroundColor = [UIColor whiteColor];
    
    self.backImageView = backImageView;
    
    [self.contentView addSubview:self.backImageView];
    
    
    UIImageView * darkImageView = [UIImageView new];
    
    darkImageView.image = ImageNamed(@"yuanjia");
    
    self.darkImageView = darkImageView;
    
    [self.backImageView addSubview:self.darkImageView];
    
    
    UIImageView * eyeImageView = [UIImageView new];
    
    eyeImageView.image = ImageNamed(@"yueduliang");
    
    self.eyeImageView = eyeImageView;
    
    [self.darkImageView addSubview:self.eyeImageView];
    
    
    UILabel * readNumLabel = [UILabel new];
    
    readNumLabel.textColor = [UIColor whiteColor];
    readNumLabel.font = [UIFont systemFontOfSize:10 * SCREENH6];
    
    
//    int x = [self getRandomNumber:0 to:9999];
//
//    readNumLabel.text = [NSString stringWithFormat:@"%d",x];
    
    self.readNumLabel = readNumLabel;
    
    [self.darkImageView addSubview:self.readNumLabel];
    
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor = ColorWithRGB(0xebebeb);
    //处理圆角
    backView.layer.cornerRadius =5.0f;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    
    UIImageView * iconImageView = [UIImageView new];
    
    iconImageView.image = ImageNamed(@"tu3");
    iconImageView.backgroundColor = [UIColor whiteColor];
    
    self.iconImageView = iconImageView;
    
    [self.backView addSubview:self.iconImageView];
    
    
    UIView * verLineView = [UIView new];
    
    verLineView.backgroundColor = ColorWithRGB(0xC9C9C9);
    
    self.verLineView = verLineView;
    
    [self.backView addSubview:self.verLineView];
    
    
    UILabel * contentLabel = [UILabel new];
    
    contentLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
    contentLabel.textColor = ColorWithRGB(0x141414);
    contentLabel.numberOfLines = 1;
    contentLabel.text = @"----";
    self.contentLabel = contentLabel;
    
    [self.backView addSubview:self.contentLabel];
}



- (void)layoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(2 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(208 * SCREENH6);
    }];
    
    [self.darkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backImageView).offset(15 * SCREENH6);
        make.bottom.mas_equalTo(self.backImageView).offset(-10 * SCREENH6);
        make.width.mas_equalTo(55 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.eyeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.darkImageView).offset(4 * SCREENH6);
        make.centerY.mas_equalTo(self.darkImageView);
        make.width.mas_equalTo(16 * SCREENH6);
        make.height.mas_equalTo(12 * SCREENH6);
    }];
    
    [self.readNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.eyeImageView.mas_trailing).offset(3 * SCREENH6);
        make.centerY.mas_equalTo(self.eyeImageView);
    }];
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.backImageView.mas_bottom).offset(10 * SCREENH6);
        make.height.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.leading.mas_equalTo(self.backView).offset(7 * SCREENH6);
        make.height.width.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.verLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.width.mas_equalTo(1 * SCREENH6);
        make.height.mas_equalTo(28 * SCREENH6);
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(8 * SCREENH6);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.verLineView.mas_trailing).offset(8 * SCREENH6);
        make.centerY.mas_equalTo(self.backView);
        make.trailing.mas_equalTo(self.backView).offset(-10 * SCREENH6);
    }];
}


-(int)getRandomNumber:(int)from to:(int)to
{
    return (int)(from + (arc4random() % (to - from + 1)));
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
